package operation;

import book.BookList;
import book.ListNode;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: mac
 * Date: 2022-09-08
 * Time: 11:04
 */
public class DelOperation implements IOperation{
    public void work(BookList bookList) {
        System.out.println("删除图书");
        System.out.println("请输入你要删除的图书名字：");
        String bookName = scanner.nextLine();
        ListNode cur = bookList.getHead();
        if (cur == null) {
            System.out.println("图书余量为空，不能删除！");
            return;
        }
        if (bookName.equals(cur.val.getName())) {
            bookList.setHead(cur.next);
            System.out.println("删除成功");
            return;
        }
        while (cur.next != null){
            if (bookName.equals(cur.next.val.getName())){
                cur.next = cur.next.next;
                System.out.println("删除成功");
                return;
            }
            cur = cur.next;
        }
        System.out.println("未找到删除图书");
    }
}
